﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Data.GameData.Interfaces;

namespace Data.GameData
{
    public class StarShip : Unit, IFleetElement, ICloneable
    {
        private double maxShipSpeed = 0;
        private double bestSpeed = 0;
        private int turnMode = 2;

        #region Constructor
        public StarShip(ShipClass type)
            : base(type, UnitType.Starship)
        {
            maxShipSpeed = type.MaxSpeed;
            turnMode = type.TurnMode;
        }

        private StarShip(StarShip ship)
        {
            Name = ship.Name;
            Type = ship.Type;
            ShipClass = ship.ShipClass.Clone() as ShipClass;

            foreach (ShipSystem sys in ship.ShipLayout)
                AddSystem(sys);
        }
        #endregion

        public int MaxShipSpeed
        {
            get { return (int)maxShipSpeed; }
        }

        public int BestSpeed
        {
            get { return (int)bestSpeed; }
        }

        public int TurnMode
        {
            get { return turnMode; }
        }

        public override void AddSystem(ShipSystem sys)
        {
            if (sys != null)
            {
                base.AddSystem(sys);

                if (sys.IsEngine)
                {
                    
                    maxShipSpeed = ShipClass.MaxSpeed + sys.Modifier;
                    turnMode = ShipClass.TurnMode + sys.Modifier;

                    bestSpeed += 1 / ShipClass.EngineSize;
                }
            }
        }

        public override void ClearLayout()
        {
            base.ClearLayout();
            maxShipSpeed = 0;
            bestSpeed = 0;
            turnMode = 2;
        }        

        #region ICloneable Members
        public override object Clone()
        {
            return new StarShip(this);
        }
        #endregion
    }
}
